package myapp.drawable_items;

import java.util.ArrayList;


import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;


public class SmallItemList {
	private ArrayList<smallItem> list;
	private static final String TAG = "SmallItemList";
	
	public SmallItemList()
	{
		list = new ArrayList<smallItem>();
	}
	
	public void add(smallItem item){
		list.add(item);
	}
	
	public void clear(){
		list.clear();
	}
	public void delete(smallItem item){
		for (smallItem i : list)
		{
			if (item == i)
				list.remove(item);
		}
	}
	
	public int size(){
		return list.size();
	}
	
	public smallItem getTouchedItem(float x, float y){
		int count = list.size();
		for (int i=0; i<count; i++){
			if (list.get(i).getTouchable() == true)
			{
				smallItem curItem = list.get(i);
				float top = curItem.getTop();
				float left = curItem.getLeft();
				float width = curItem.getWidth();
				float height = curItem.getHeight();
				Log.d(TAG, "GetItemTouch : x=" + x + " y=" +y + " top=" + top + " left=" + left + " w=" + width + " h=" + height);
				if (x > left && y>top &&
						x< left + curItem.getHeight() &&
						y < top + curItem.getWidth())
					return curItem;
			}
		}
		return null;
	}
	
	public void DrawAllItems(Canvas canvas, Paint paint){
		Log.d(TAG, "Draw Items : Before the loop" + list.size());
		for (smallItem item : list) {
			canvas.drawBitmap(item.getBitmap(), item.getLeft(), item.getTop(), paint);
			Log.d(TAG, "Draw Items" + item.getTop() + " " + item.getLeft());
		}
	}
}
